/*
<CALENDAR-Tool To Perform Calendar Related Functions.>
    Copyright (C) <2011>  <SHIVAM MATHUR--shivam_jpr@hotmail.com>

    This program is free software: you can redistribute it and/or modify
    the software until it is not mentioned in the source,
    under the terms of the GNU Affero General Public License as
    published by the Free Software Foundation, either version 3 of the
    License, or any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Affero General Public License for more details.

    You should have received a copy of the GNU Affero General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.

	Note that the username is- 	shivam
	and the password is- 		cool
*The password can be changed but it must be notified with the distribution and scapping the password feature would mean copyright infringement
*The terms and conditions given below or in the licence.txt(https://sourceforge.net/projects/c-cpp-calender/files/licence.txt) follow to every part of the program until and unless explictly mentioned
 these terms and conditons might change without your prior information and in any case the licence terms as
 mentioned in the latest version of -(https://sourceforge.net/projects/c-cpp-calender/files/licence.txt)
 would be valid and applicable.
*The redistributors are expected to use the screenshots provided with the project than rather than creating their own.
*The icon of Calendar must not be changed and in any case the icon provided with the project must be used.

The following program perform the functions for which a calendar is used
MADE BY SHIVAM MATHUR
:)
*/
#include "func.cpp"                     						//Contains all the User-Defined functions accessed in the program

int main (int argc, char *argv[])		      					//Main function
{
/*******************************************************Password roadblock***************************************************************/    
	SetConsoleTitle("CALENDAR 2.0- By SHIVAM");									
	do{														
		ket=0;met=0;	
		ri=79;		bt=25;
		cal.setscr();											//Resetting the screen size
		cal.roadblock();										//conforms if password or username do not match
		if (a==1)
    		{

				ri=79;		bt=28;
				cal.setscr();
				SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 12);	//Function to change the colour of output handle in the console		
				cal.gotoxy(28, 8);		cout<<"___________________";
				cal.gotoxy(28,16);		cout<<"___________________";
				cal.gotoxy( 0,21);		cout<<"________________________________________________________________________________\n";
				SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
				cal.gotoxy(34, 8);		cout<<"WELCOME";
				cal.gotoxy(20,18);		cout<<"The PASSWORD or USERNAME is not correct\n\n\n";
   				cal.gotoxy(20,19);		cout<<"\t1. Press 'y/Y' to Enter Again\n";
   				cal.gotoxy(20,20);		cout<<"\t2. Press any other key to EXIT\n";
				SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 2);
				cal.gotoxy(20,23);		cout<<"Enter : ";
				SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
				cal.gotoxy(29,23);		cin>>pchoice;
				if(pchoice!='y' && pchoice!='Y')
					{
						cal.gotoxy(20,25); cout<<"You chose to exit";
						cal.gotoxy(20,26); cout<<"Good BYE\n";
						cout<<"\nPress any key to end";
      					cal.GetCh();
      					exit(0); 							 //Exiting the program as per users choice
					}
				else 		ket=2;
				if(a!=1) 	met=2; 
			}
	}	while(ket==2 && met!=2);
/***************************************************************************************************************************************/
start:
  	cal.docls();													//Cleares the screen
	ri=79;		bt=27;
	cal.setscr();

/********************************************************CREDITS************************************************************************/
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////			This code (from 2 above lines to 20 lines under this line) must be there with every distribution					   //
///				Removing this part to the code is not allowed in any case,the doing so would directly mean without 					  ///
//				any argument the violation of the free license provided and a case of copyright infringement.						 ////	
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 7);
	cal.gotoxy( 0,14); 	cout<<"CREDITS\n";
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 8);
	cal.gotoxy( 5,15); 	cout<<"           88           88                                             \n";
	cal.gotoxy( 5,16); 	cout<<"           88           88                                             \n";
	cal.gotoxy( 5,17);	cout<<"           88                                                          \n";
	cal.gotoxy( 5,18); 	cout<<",adPPYba,  88,dPPYba,   88  8b       d8  ,adPPYYba,  8 ,dPYba,,adPYba, \n";
	cal.gotoxy( 5,19); 	cout<<"SSS    sa  88P'     8a  88  `8b     d8'  aa     `Y8  88P'    88     8as\n";
	cal.gotoxy( 5,20); 	cout<<"   S8ba    88       88  88   `8b   d8'   ,adPPPPP88  88      88      88\n";
	cal.gotoxy( 5,21); 	cout<<"aa    DSD  88       88  88    `8b,d8'    88,    ,88  88      88      88\n";
	cal.gotoxy( 5,22); 	cout<<"SaYbbdPa'  88       88  88      s8s      `s8bbdPsY8  88      88      88\n";
	cal.gotoxy( 0, 0);
/***************************************************************************************************************************************/
	

	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),12);
	cal.gotoxy( 0, 0);		cout<<"________________________________________________________________________________\n";	//welcome
	cal.gotoxy( 0,11);		cout<<"________________________________________________________________________________\n";
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),15);
	cal.gotoxy(28, 0);		cout<<"Welcome to the Calendar";
	cal.gotoxy(70, 0);		cout<<"VER 2.0";
	cout<<"\n\n";
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),7);
	cout<<"OPTIONS";
	cal.gotoxy( 0, 4);
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),15);
	cout<<"\t1. Enter 1 to print day of any date\n";					//Options of the program
	cout<<"\t2. Enter 2 to print calendar of any month\n";
	cout<<"\t3. Enter 3 to print calendar of any year\n";
	cout<<"\t4. Enter 4 to find the dates in a month on which a day occurs\n\n\t";
    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),10);
    cal.gotoxy(60,26); cout<<"Press 5 to exit";
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),2);
	cal.gotoxy( 8, 9); cout <<"Enter your choice:\t";
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),15);
	cin>>numstr; 
	if(isdigit(numstr[0])==0) /* 
								Caution
								Conditional statements to get a interger from the user
								even if he enters garbage which may hang the program		
							 */
		{
			ch=7;/* ch=7 to invoke exception of ch>4*/ 
			cal.repeat() ; 
			if  (ch1=='y'||ch1=='Y') 
				goto start;
		} 
	else ch=atol(numstr); 
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),15);
/***************************************************************************************************************************************/
	if (ch==1)															//Prints the day
		{
begi1:
     		do{	
				cal.docls();
         	fla=0;
   			if(again==1)
         	{
				SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),10);
				cal.gotoxy(30, 4);		cout<<"!!! ENTER AGAIN !!!";
            }
			SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),2);
			cal.gotoxy(28, 7);   	cout<<"______________________";
			cal.gotoxy(28,20);   	cout<<"______________________\n";
			SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),15);
			cal.gotoxy(34, 7);   	cout<<"DAY-FINDER";
			cal.gotoxy(28, 9);		cout<<"Enter the date(DD)\n";
			cal.gotoxy(28,10);		cin>>numstr; if(isdigit(numstr[0])==0) {again=1; goto begi1;} else date=atol(numstr);
			cal.gotoxy(28,12);		cout<<"Enter the month\n";
			cal.gotoxy(28,13);		cin>>numstr; if(isdigit(numstr[0])==0) {strcpy(str,numstr); lim=12;	strcase='m';	cal.chkstr(); mon=strno;} else mon=atol(numstr);
			cal.gotoxy(28,15);		cout<<"Enter the year(YYYY)\n";
			cal.gotoxy(28,16);		cin>>numstr; if(isdigit(numstr[0])==0) {again=1; goto begi1;} else year=atol(numstr);
			cal.chkdate();
			}while(again==1);
			x=cal.dayno();
			if(flag==0)
				{
					cal.gotoxy(28,18);		cout<<"The day was : ";
				}
			else if(flag==1)
				{
					cal.gotoxy(28,18);		cout<<"The day will be : ";
				}
			else if(flag==2)
				{
					cal.gotoxy(28,18);		cout<<"Today is a : ";
				}
			SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),12);
			cout<<week[x]<<"\n";
		}
/***************************************************************************************************************************************/
	if (ch==2)															//prints the calendar of the month
		{
begi2:		do{
			cal.docls();
   			if(again==1)
         	{
				SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),10);
         		cal.gotoxy(28, 4);	cout<<"!!! ENTER AGAIN !!!";
            }
			SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),2);
			cal.gotoxy(28, 7);   	cout<<"____________________";
			cal.gotoxy(28,15);   	cout<<"____________________\n";
			SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),15);
			cal.gotoxy(31, 7);   	cout<<"MONTH-CALENDAR";
			cal.gotoxy(28, 9); 		cout<<"Enter the month\n";
			cal.gotoxy(28,10); 		cin>>numstr; if(isdigit(numstr[0])==0) {strcpy(str,numstr); lim=12;	strcase='m';	cal.chkstr(); mon=strno;} else {mon=atol(numstr);fla = 0;}
			cal.gotoxy(28,12);		cout<<"Enter the year{YYYY}\n";
			cal.gotoxy(28,13);		cin>>numstr; if(isdigit(numstr[0])==0) {again=1; goto begi2;} else year=atol(numstr);
			date=1;
         	counter = mon;
		 	cal.chkdate();
			}while(again==1);
			cal.docls();
			cal.monthcal();
		}
/***************************************************************************************************************************************/
	if (ch==3)															//prints the calendar of the year
		{
begi3:		
			do{
			cal.docls();
   			if(again == 1)
  				{
					SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),10);
         			cal.gotoxy(29, 4);	cout<<"!!! ENTER AGAIN !!!";
				}
			again=0;
			SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),2);
			cal.gotoxy(28, 7);   	cout<<"_____________________";
			cal.gotoxy(28,13);   	cout<<"_____________________\n";
			SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),15);
			cal.gotoxy(31, 7);   	cout<<"YEARLY-CALENDAR";
			cal.gotoxy(28, 9);		cout<<"Enter the year(YYYY)\n";
			cal.gotoxy(28,11);		cin>>numstr; if(isdigit(numstr[0])==0) {again=1; goto begi3;} else year=atol(numstr);
			date=1;
			mon=1;
			cal.chkdate();
			}while(again==1);
      		cal.docls();

			for (counter = 1; counter <= 12; counter++)
 				{
					cal.printAll();
 				}
		}
/***************************************************************************************************************************************/
	if (ch==4)															//prints the dates on which a day lies in a month
		{
begi4:
			do{
			cal.docls();
   			if(again == 1)
         		{
					SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),10);
         			cal.gotoxy(29, 4);	cout<<"!!! ENTER AGAIN !!!";
				}
			again=0;
			strno='\0';
			fla=0;
			SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),2);
			cal.gotoxy(28, 7);   	cout<<"________________________";
			cal.gotoxy(28,18);   	cout<<"________________________\n";
			SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),15);
			cal.gotoxy(35, 7);   	cout<<"DATE-FINDER";
			cal.gotoxy(28, 9);		cout<<"Enter the day\n";
			cal.gotoxy(28,10);		cin>>numstr; if(isdigit(numstr[0])==0){strcpy(str,numstr);lim=6;strcase='d';cal.chkstr();daynum=strno;}else{if (atol(numstr)<8){daynum=atoi(numstr);ket=0;}else if(strno>7 || atol(numstr)>7){again=1;goto begi4;}}			
			cal.gotoxy(28,12); 		cout<<"Enter the month\n";
			cal.gotoxy(28,13);		cin>>numstr; if(isdigit(numstr[0])==0) {strcpy(str,numstr); lim=12;	strcase='m';	cal.chkstr(); mon=strno;}else mon=atol(numstr);
			cal.gotoxy(28,15);		cout<<"Enter the year\n";
			cal.gotoxy(28,16);		cin>>numstr; if(isdigit(numstr[0])==0) {again=1; goto begi4;} else year=atol(numstr);
			cout<<"\n";			cout<<"\n";
			date=1;
			cal.chkdate();
			}while(again==1);
			cal.docls();
			if(daynum==7)		daynum=0;
			cal.day2date ();
			goto rep;
		}
/***************************************************************************************************************************************/
	if (ch==5)                                                //BYE   (function to exit)
   		{
      		cal.gotoxy(25,26);	exit(0);
		}
/***************************************************************************************************************************************/
	else
rep:
		cal.repeat() ;
	if  (ch1=='y'||ch1=='Y')
		goto start;

return 0;						//end of main statement
}
//end of code
//made by shivam mathur
